package com.iseastar.guojiang.print;

import com.iseastar.guojiang.model.PrintBean;
import com.shouhuobao.take.utils.StringUtils;

import printpp.printpp_yt.PrintPP_CPCL;

/**
 * Created by joker on 2017/7/27.
 * 打印面单类
 */
public class PrintDataUtils {
    public static boolean printData(PrintPP_CPCL iPrinter, PrintBean printBean) {
        if (printBean.getExpressCompany().contains("韵达")) {
            return sendYDPrintData(iPrinter, printBean);
        } else if (printBean.getExpressCompany().contains("圆通")) {
            return sendYTPrintData(iPrinter, printBean);
        } else if (printBean.getExpressCompany().contains("申通")) {
            return sendSTPrintData(iPrinter, printBean);
        } else if (printBean.getExpressCompany().contains("中通")) {
            return sendZTPrintData(iPrinter, printBean);
        }
        return false;
    }

    /**
     * 韵达打印机 打印韵达面单
     *
     * @param iPrinter
     * @param printBean
     * @return
     */
    private static boolean sendYDPrintData(PrintPP_CPCL iPrinter, PrintBean printBean) {
        int width = 72 * 8;
        int height = 150 * 8 + 20;
        int senderAddressHeight = 0;
        String numberStr = StringUtils.getNumberString(printBean.getSenderAddress());
        if (!StringUtils.isEmpty(numberStr)) {
            if (numberStr.length() % 2 == 0) {
                if ((printBean.getSenderAddress().length() - numberStr.length()) - numberStr.length() / 2 > 28) {
                    senderAddressHeight = 17;
                }
            } else {
                if ((printBean.getSenderAddress().length() - numberStr.length()) - numberStr.length() / 2 + 1 > 28) {
                    senderAddressHeight = 17;
                }
            }
        } else {
            if (printBean.getSenderAddress().length() - numberStr.length() > 28) {
                senderAddressHeight = 17;
            }
        }

        iPrinter.pageSetup(width, height);
        iPrinter.drawBox(4, 0, 0, width, height);


        //第一联
        iPrinter.drawLine(2, 0, 354, width, 354, true);//第一联横线1
        iPrinter.drawLine(8, 0, 470, width, 470, true);//第一联横线2
        iPrinter.drawLine(2, 0, 574, width, 574, true);//第一联横线3
        iPrinter.drawLine(8, 0, 622, width, 622, true);//第一联横线4
        iPrinter.drawLine(2, 0, 682, width, 682, true);//第一联横线5

        iPrinter.drawLine(2, 150, 354, 150, 470, true);//第一联竖线1

        //第二联
        iPrinter.drawLine(2, 0, 775, width, 775, true);
        iPrinter.drawLine(2, 0, 950, width, 950, true);
        //第三联
        iPrinter.drawLine(2, 0, 1055, width, 1055, true);
        //上联
        if (StringUtils.isEmpty(printBean.getSourceSite())) {
            iPrinter.drawText(10, 20, 520 - 160, 20, "始发网点：", 1, 0, 0, false, false);
        } else {
            iPrinter.drawText(10, 20, 520 - 160, 20, "始发网点：" + printBean.getSourceSite(), 1, 0, 0, false, false);
        }
        iPrinter.drawText(width - 150, 20, 150, 50, "已安检", 4, 0, 0, false, false);
        iPrinter.drawText(10, 40, 520, 20, "姓名：" + printBean.getSenderName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 60, 520, 20, "发件公司：", 1, 0, 0, false, false);
        iPrinter.drawText(10, 80, 540, 20, "发件地址：" + printBean.getSenderAddress(), 1, 0, 0, false, false);

        iPrinter.drawText(10, 100 + senderAddressHeight, 520, 20, "送达地址：", 1, 0, 0, false, false);

        iPrinter.drawText(10, 120 + senderAddressHeight, 520, 25, "收件人：" + printBean.getReceiverName(), 2, 0, 0, false, false);
        iPrinter.drawText(10, 145 + senderAddressHeight, 520, 25, "电话：" + printBean.getReceiverPhone(), 2, 0, 0, false, false);
        iPrinter.drawText(10, 170 + senderAddressHeight, 520, 25, "收件公司：", 2, 0, 0, false, false);
        iPrinter.drawText(10, 195 + senderAddressHeight, 525, 25, "收件地址：" + printBean.getReceiverAddress(), 2, 0, 0, false, false);
        iPrinter.drawText(10, 268 + senderAddressHeight, 255, 48, "集包地:" + printBean.getCollectLocation(), 3, 0, 0, false, false);

        iPrinter.drawBarCode(375, 268, printBean.getCollectCode(), 1, 0, 2, 70);
        iPrinter.drawText(width - 80, 338, 80, 20, printBean.getCollectCode(), 1, 0, 0, false, false);
        if (StringUtils.isEmpty(printBean.getCategory())) {
            iPrinter.drawText(10, 360, 120, 100, "物品类型：其他", 2, 0, 1, false, false);
        } else {
            iPrinter.drawText(10, 360, 120, 100, "物品类型：" + printBean.getCategory(), 2, 0, 1, false, false);
        }
        iPrinter.drawText(150, 374, 480, 100, printBean.getBigCode(), 5, 0, 1, false, false);
        iPrinter.drawBarCode(190, 490, printBean.getExpressNumber(), 1, 0, 2, 70);
        iPrinter.drawText(10, 588, 200, 24, "运单编号", 2, 0, 0, false, false);
        iPrinter.drawText(210, 588, 200, 24, printBean.getExpressNumber(), 2, 0, 0, false, false);
        iPrinter.drawText(10, 630, 200, 24, "收件人/代签人：", 2, 0, 0, false, false);
        iPrinter.drawText(width - 300, 630, 300, 24, "签收日期:  年  月  日", 2, 0, 0, false, false);
        iPrinter.drawText(width - 300, 654, 300, 24, "火箭包裹- " + printBean.getBagCode(), 2, 0, 0, false, false);
        //中联
        iPrinter.drawBarCode(10, 707, printBean.getExpressNumber(), 1, 0, 2, 50);
        iPrinter.drawText(10, 760, 200, 24, printBean.getExpressNumber(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 785, 200, 20, "发件人：" + printBean.getSenderName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 805, 200, 20, "电话：" + printBean.getSenderPhone(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 825, 540, 20, "发件地址：" + printBean.getSenderAddress(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 845 + senderAddressHeight, 200, 20, "收件人：" + printBean.getReceiverName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 865 + senderAddressHeight, 200, 20, "电话：" + printBean.getReceiverPhone(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 885 + senderAddressHeight, 540, 20, "收件地址：" + printBean.getReceiverAddress(), 1, 0, 0, false, false);
        //下联
        iPrinter.drawBarCode(10, 985, printBean.getExpressNumber(), 1, 0, 2, 50);
        iPrinter.drawText(10, 1038, 200, 24, printBean.getExpressNumber(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1061, 200, 20, "发件人：" + printBean.getSenderName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1081, 200, 20, "电话：" + printBean.getSenderPhone(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1101, 540, 20, "发件地址：" + printBean.getSenderAddress(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1121 + senderAddressHeight, 200, 20, "收件人：" + printBean.getReceiverName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1141 + senderAddressHeight, 200, 20, "电话：" + printBean.getReceiverPhone(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1161 + senderAddressHeight, 540, 20, "收件地址：" + printBean.getReceiverAddress(), 1, 0, 0, false, false);

        iPrinter.print(0, 0);

        String string = iPrinter.printerStatus();
        if ("Printing".equals(string)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 圆通打印机 打印圆通面单
     *
     * @param iPrinter
     * @param printBean
     * @return
     */
    private static boolean sendYTPrintData(PrintPP_CPCL iPrinter, PrintBean printBean) {
        int width = 586;
        int height = 1328;
        iPrinter.pageSetup(width, height);
        //第一联
        //第一联横线1
        iPrinter.drawLine(2, 0, 240, width - 2, 240, false);
        //第一联横线2
        iPrinter.drawLine(2, 0, 384, width - 2, 384, false);
        //第一联横线3
        iPrinter.drawLine(2, 0, 552, width - 2 - 40, 552, false);
        //第一联竖线1，从左到右]
        iPrinter.drawLine(2, 40, 384, 40, 680, false);
        //第一联竖线2，从左到右
        iPrinter.drawLine(2, 408, 552, 408, 680, false);
        //第一联竖线3，从左到右
        iPrinter.drawLine(2, width - 2 - 40, 384, width - 2 - 40, 680, false);
        //派件联
        iPrinter.drawText(568 - 32 + 3 + 8, 384 + 128, 32, 96, "派  件  联", 2, 0, 0, false, false);
        //收件人
        iPrinter.drawText(2 + 4, 384 + 28, 32, 120, "收件人", 3, 0, 1, false, false);
        //寄件人
        iPrinter.drawText(2 + 8, 552 + 22, 32, 96, "寄件人", 2, 0, 0, false, false);
        //签收人
        iPrinter.drawText(2 + 424 - 8, 552 + 8, "签收人:", 2, 0, 0, false, false);
        //时间
        iPrinter.drawText(2 + 424, 680 - 26 - 8, "日期:", 2, 0, 0, false, false);

        //第二联
        //第二联横线1
        iPrinter.drawLine(2, 0, 716 + 32, 568 + 16, 716 + 32, false);
        //第二联左侧竖线1
        iPrinter.drawLine(2, 0, 716 + 160, 568 - 32 + 16, 716 + 160, false);
        //第二联右侧竖线1
        iPrinter.drawLine(2, 40, 716 + 160 + 96, 568 - 32 + 8, 716 + 160 + 96, false);
        //第二联横线2
        iPrinter.drawLine(2, 40, 706 + 32, 40, 706 + 288, false);
        //第二联竖线2
        iPrinter.drawLine(2, 568 - 32 + 8, 716 + 32, 568 - 32 + 8, 700 + 16 + 288, false);
        //收件联
        iPrinter.drawText(568 - 32 + 3 + 8, 716 + 32 + 80, 32, 93, "收  件  联", 2, 0, 0, false, false);
        //收件
        iPrinter.drawText(2 + 4, 716 + 32 + 16, 32, 96, "收件人", 2, 0, 0, false, false);
        //内容
        iPrinter.drawText(2 + 4, 716 + 160 + 3, 32, 120, "寄件人", 2, 0, 0, false, false);

        //第三联
        iPrinter.drawLine(2, 0, 1096, 568 + 16, 1096, false);
        iPrinter.drawLine(2, 0, 1096 + 104 - 8 + 4, 568 - 32 + 8, 1096 + 104 - 8 + 4, false);
        iPrinter.drawLine(2, 0, 1096 + 104 + 104 - 8, 568 - 32 + 8, 1096 + 104 + 104 - 8, false);
        iPrinter.drawLine(2, 40, 1096 + 104 + 104 + 96 + 4 - 4 - 2 - 8 - 4, 568 - 32 + 8, 1096 + 104 + 104 + 96 + 4 - 4 - 2 - 8 - 4, false);
        iPrinter.drawLine(2, 40, 1096, 40, 1432 - 4 - 16 + 4, false);
        iPrinter.drawLine(2, 568 - 32 + 8, 1096, 568 - 32 + 8, 1432 - 4 - 16 + 4, false);
        //寄件联
        iPrinter.drawText(568 - 32 + 3 + 8, 1096 + 104 + 16, 32, 96, "寄  件  联", 2, 0, 0, false, false);
        //收件人
        iPrinter.drawText(2 + 4, 1096 + 5, 32, 96, "收件人", 2, 0, 0, false, false);
        //寄件人
        iPrinter.drawText(2 + 4, 1096 + 104 + 5, 32, 96, "寄件人", 2, 0, 0, false, false);
        //内容
        iPrinter.drawText(2 + 4, 1096 + 104 + 104 + 1, 32, 120, "内容品名", 2, 0, 0, false, false);
        //包号
        if (!StringUtils.isEmpty(printBean.getBigCode()) && printBean.getBigCode().length() < 5) {
            iPrinter.drawText(2 + 240, 128 + 16 + 8, printBean.getBigCode(), 5, 0, 0, false, false);
        } else {
            iPrinter.drawText(2 + 10, 128 + 16 + 8, printBean.getBigCode(), 5, 0, 0, false, false);
        }
        //运单条码
        if (printBean.getExpressNumber().length() <= 12 && printBean.getExpressNumber().length() >= 10) {
            iPrinter.drawBarCode(32 + 100, 240 + 16, printBean.getExpressNumber(), 1, 0, 3, 80);
            iPrinter.drawText(2 + 96 + 76, 340, printBean.getExpressNumber(), 3, 0, 0, false, false);
        } else {
            iPrinter.drawBarCode(32, 240 + 16, printBean.getExpressNumber(), 1, 0, 3, 80);
            iPrinter.drawText(2 + 96 + 76 - 64, 340, printBean.getExpressNumber(), 3, 0, 0, false, false);
        }
        //收件人信息（姓名 + 手机号码）
        iPrinter.drawText(2 + 4 + 32 + 8, 264 + 128, 480, 32, printBean.getReceiverName() + "  " + printBean.getReceiverPhone(), 3, 0, 1, false, false);
        //收件人地址
        iPrinter.drawText(2 + 4 + 32 + 8, 372 + 40 + 22, 448, 120, printBean.getReceiverAddress(), 3, 0, 1, false, false);
        //寄件人（姓名 + 手机号码）
        iPrinter.drawText(2 + 4 + 32 + 8, 552 + 8, 480, 24, printBean.getSenderName() + "  " + printBean.getSenderPhone(), 2, 0, 0, false, false);
        //寄件人地址
        iPrinter.drawText(2 + 4 + 32 + 8, 552 + 40, 344, 112, printBean.getSenderAddress(), 2, 0, 0, false, false);
        /*------收件联------*/
        //运单号和订单号
        iPrinter.drawText(8, 716 + 3, "运单号:" + printBean.getExpressNumber(), 2, 0, 0, false, false);
        //收件人（姓名+手机号）
        iPrinter.drawText(2 + 8 + 32 + 8, 628 + 128, 480, 24, printBean.getReceiverName() + "  " + printBean.getReceiverPhone(), 2, 0, 0, false, false);
        //收件人地址
        iPrinter.drawText(2 + 8 + 32 + 8, 716 + 32 + 40 + 2, 424, 80, printBean.getReceiverAddress(), 2, 0, 0, false, false);
        //寄件人（姓名 + 手机号码)
        iPrinter.drawText(2 + 4 + 32 + 8, 706 + 160 + 18, 432, 24, printBean.getSenderName() + "  " + printBean.getSenderPhone(), 2, 0, 0, false, false);
        //寄件人地址
        iPrinter.drawText(2 + 4 + 32 + 8, 706 + 160 + 18 + 24, 456, 72, printBean.getSenderAddress(), 2, 0, 0, false, false);

         /*------寄件联------*/
        //第三联运单号条码
        if (printBean.getExpressNumber().length() <= 12 && printBean.getExpressNumber().length() >= 10) {
            iPrinter.drawBarCode(100 + 140, 1000 + 8, printBean.getExpressNumber(), 1, 0, 3, 56);
            iPrinter.drawText(2 + 312, 1008 + 56 + 4, printBean.getExpressNumber(), 2, 0, 0, false, false);
        } else {
            iPrinter.drawBarCode(105, 1000 + 8, printBean.getExpressNumber(), 1, 0, 3, 56);
            iPrinter.drawText(2 + 312 - 64, 1008 + 56 + 4, printBean.getExpressNumber(), 2, 0, 0, false, false);
        }
        //收件人（姓名 + 手机号码）
        iPrinter.drawText(2 + 8 + 32 + 8 + 4 + 4, 1096 + 8, 480, 24, printBean.getReceiverName() + "  " + printBean.getReceiverPhone(), 2, 0, 0, false, false);
        //收件地址
        iPrinter.drawText(2 + 8 + 32 + 8 + 4 + 4, 1096 + 8 + 24 + 8, 456, 64, printBean.getReceiverAddress(), 2, 0, 0, false, false);
        //寄件人（姓名 + 手机号码)
        iPrinter.drawText(2 + 4 + 32 + 8, 1096 + 104 + 8, 480, 24, printBean.getSenderName() + "  " + printBean.getSenderPhone(), 2, 0, 0, false, false);
        //寄件人地址
        iPrinter.drawText(2 + 4 + 32 + 8, 1096 + 104 + 8 + 24 + 8, 456, 72, printBean.getSenderAddress(), 2, 0, 0, false, false);
        //内容
        if (StringUtils.isEmpty(printBean.getCategory())) {
            iPrinter.drawText(2 + 4 + 32 + 8 + 4 + 4, 1096 + 104 + 104 + 8, 432, 156, "火箭投递包裹 - " + printBean.getBagCode() + " ,物品类型: 其他", 2, 0, 0, false, false);
        } else {
            iPrinter.drawText(2 + 4 + 32 + 8 + 4 + 4, 1096 + 104 + 104 + 8, 432, 156, "火箭投递包裹 - " + printBean.getBagCode() + " ,物品类型: " + printBean.getCategory(), 2, 0, 0, false, false);
        }
        iPrinter.drawText(width - 180, 79, 180, 50, "已安检", 4, 0, 0, false, false);
        iPrinter.print(1, 0);

        String string = iPrinter.printerStatus();
        if ("Printing".equals(string) || "Print Read Error".equals(string)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 申通打印机 打印申通面单
     *
     * @param iPrinter
     * @param printBean
     * @return
     */
    private static boolean sendSTPrintData(PrintPP_CPCL iPrinter, PrintBean printBean) {
        int width = 72 * 8;
        int height = 150 * 9;

        iPrinter.pageSetup(width, height + 20);
        //边框
        iPrinter.drawBox(4, 0, 0, width, height);
        iPrinter.drawLine(4, 0, 940, width, 940, true);
        //第一联
        //第一联横线1
        iPrinter.drawLine(2, 0, 72, width, 72, true);
        //第一联横线2
        iPrinter.drawLine(2, 0, 160, width, 160, true);
        //第一联横线3
        iPrinter.drawLine(2, 0, 280, width, 280, true);
        //第一联横线4
        iPrinter.drawLine(2, 0, 384, width, 384, true);
        //第一联横线5
        iPrinter.drawLine(2, 0, 488, width, 488, true);
        //第一联横线6
        iPrinter.drawLine(2, 0, 650, width, 650, true);
        //第一联竖线1
        iPrinter.drawLine(2, 44, 160, 44, 488, true);

        //第二联
        iPrinter.drawLine(2, 0, 1040, width, 1040, true);
        iPrinter.drawLine(2, 0, 1156, width, 1156, true);
        iPrinter.drawLine(2, 0, 1260, width, 1260, true);
        //第二联竖线1
        iPrinter.drawLine(2, 44, 1156, 44, height, true);
        //第二联竖线2
        iPrinter.drawLine(2, 440, 1156, 440, height, true);

        //上联
        iPrinter.drawText(90, 88, width - 180, 64, printBean.getBigCode(), 4, 0, 1, false, false);
        //收件
        iPrinter.drawText(10, 196, 24, 48, "收件", 2, 0, 0, false, false);
        //收件人信息（姓名 + 手机号码）
        iPrinter.drawText(50, 168, 392, 24, printBean.getReceiverName() + "  " + printBean.getReceiverPhone(), 2, 0, 1, false, false);
        //收件人地址
        iPrinter.drawText(50, 200, width - 50, 48, printBean.getReceiverAddress(), 2, 0, 1, false, false);
        //寄件
        iPrinter.drawText(10, 308, 24, 48, "寄件", 2, 0, 0, false, false);
        //寄件人（姓名 + 手机号码）
        iPrinter.drawText(50, 288, 392, 24, printBean.getSenderName() + "  " + printBean.getSenderPhone(), 2, 0, 0, false, false);
        //寄件人地址
        iPrinter.drawText(50, 320, width - 50, 48, printBean.getSenderAddress(), 2, 0, 0, false, false);
        //服务
        iPrinter.drawText(10, 412, 24, 48, "服务", 2, 0, 0, false, false);
        if (StringUtils.isEmpty(printBean.getCategory())) {
            iPrinter.drawText(50, 392, 500, 24, "火箭投递包裹-" + printBean.getBagCode() + " ,物品类型: 其他", 2, 0, 0, false, false);
        } else {
            iPrinter.drawText(50, 392, 500, 24, "火箭投递包裹-" + printBean.getBagCode() + " ,物品类型:" + printBean.getCategory(), 2, 0, 0, false, false);
        }
        iPrinter.drawText(50, 420, 392, 24, "已安检", 3, 0, 1, false, false);
        //运单条码
        iPrinter.drawBarCode(116, 500, printBean.getExpressNumber(), 1, 0, 2, 108);
        iPrinter.drawText(136, 616, 480, 32, printBean.getExpressNumber(), 3, 0, 1, false, false);
        //免责声明
        iPrinter.drawText(10, 770, width - 20, 80, "快件送达收件人地址，经收件人或收件人（寄件人）允许的代收人签字，视为送达您的签字代表您已验收此包裹，并已确认商品信息无误，包装完好，没有划痕，破损等表面质量问题。", 1, 0, 0, false, false);

        //下联
        //运单条码
        iPrinter.drawBarCode(116, 1045, printBean.getExpressNumber(), 1, 0, 2, 70);
        iPrinter.drawText(136, 1115, 480, 24, printBean.getExpressNumber(), 4, 0, 1, false, false);
        //寄件
        iPrinter.drawText(10, 1156 + 20, 24, 48, "寄件", 2, 0, 0, false, false);
        //寄件人（姓名 + 手机号码）
        iPrinter.drawText(50, 1156 + 8, 392, 24, printBean.getSenderName() + "  " + printBean.getSenderPhone(), 2, 0, 0, false, false);
        //寄件人地址
        iPrinter.drawText(50, 1156 + 40, 392, 48, printBean.getSenderAddress(), 2, 0, 0, false, false);
        //收件
        iPrinter.drawText(10, 1260 + 20, 24, 48, "收件", 2, 0, 0, false, false);
        //收件人信息（姓名 + 手机号码）
        iPrinter.drawText(50, 1260, 392, 24, printBean.getReceiverName() + "  " + printBean.getReceiverPhone(), 2, 0, 1, false, false);
        //收件人地址
        iPrinter.drawText(50, 1260 + 32, 392, 48, printBean.getReceiverAddress(), 2, 0, 1, false, false);
        iPrinter.drawText(448, 1156 + 8, 100, 24, "签收人: ", 2, 0, 0, false, false);
        iPrinter.drawText(448, 1260 + 8, 100, 24, "时间: ", 2, 0, 0, false, false);

        iPrinter.print(0, 0);

        String string = iPrinter.printerStatus();
        if ("Printing".equals(string) || "Print Read Error".equals(string)) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * 中通打印机 打印中通面单
     *
     * @param iPrinter
     * @param printBean
     * @return
     */
    private static boolean sendZTPrintData(PrintPP_CPCL iPrinter, PrintBean printBean) {
        int width = 72 * 8;
        int height = 150 * 8 + 20;
        int senderAddressHeight = 0;
        String numberStr = StringUtils.getNumberString(printBean.getSenderAddress());
        if (!StringUtils.isEmpty(numberStr)) {
            if (numberStr.length() % 2 == 0) {
                if ((printBean.getSenderAddress().length() - numberStr.length()) - numberStr.length() / 2 > 28) {
                    senderAddressHeight = 17;
                }
            } else {
                if ((printBean.getSenderAddress().length() - numberStr.length()) - numberStr.length() / 2 + 1 > 28) {
                    senderAddressHeight = 17;
                }
            }
        } else {
            if (printBean.getSenderAddress().length() - numberStr.length() > 28) {
                senderAddressHeight = 17;
            }
        }

        iPrinter.pageSetup(width, height);
        iPrinter.drawBox(4, 0, 0, width, height);


        //第一联
        iPrinter.drawLine(2, 0, 354, width, 354, true);//第一联横线1
        iPrinter.drawLine(8, 0, 470, width, 470, true);//第一联横线2
        iPrinter.drawLine(2, 0, 574, width, 574, true);//第一联横线3
        iPrinter.drawLine(8, 0, 622, width, 622, true);//第一联横线4
        iPrinter.drawLine(2, 0, 682, width, 682, true);//第一联横线5

        iPrinter.drawLine(2, 150, 354, 150, 470, true);//第一联竖线1

        //第二联
        iPrinter.drawLine(2, 0, 775, width, 775, true);
        iPrinter.drawLine(2, 0, 950, width, 950, true);
        //第三联
        iPrinter.drawLine(2, 0, 1055, width, 1055, true);
        //上联
        if (StringUtils.isEmpty(printBean.getSourceSite())) {
            iPrinter.drawText(10, 20, 520 - 160, 20, "始发网点：", 1, 0, 0, false, false);
        } else {
            iPrinter.drawText(10, 20, 520 - 160, 20, "始发网点：" + printBean.getSourceSite(), 1, 0, 0, false, false);
        }
        iPrinter.drawText(width - 150, 20, 150, 50, "已安检", 4, 0, 0, false, false);
        iPrinter.drawText(10, 40, 520, 20, "姓名：" + printBean.getSenderName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 60, 520, 20, "发件公司：", 1, 0, 0, false, false);
        iPrinter.drawText(10, 80, 540, 20, "发件地址：" + printBean.getSenderAddress(), 1, 0, 0, false, false);

        iPrinter.drawText(10, 100 + senderAddressHeight, 520, 20, "送达地址：", 1, 0, 0, false, false);

        iPrinter.drawText(10, 120 + senderAddressHeight, 520, 25, "收件人：" + printBean.getReceiverName(), 2, 0, 0, false, false);
        iPrinter.drawText(10, 145 + senderAddressHeight, 520, 25, "电话：" + printBean.getReceiverPhone(), 2, 0, 0, false, false);
        iPrinter.drawText(10, 170 + senderAddressHeight, 520, 25, "收件公司：", 2, 0, 0, false, false);
        iPrinter.drawText(10, 195 + senderAddressHeight, 525, 25, "收件地址：" + printBean.getReceiverAddress(), 2, 0, 0, false, false);
        iPrinter.drawText(10, 268 + senderAddressHeight, 255, 48, "集包地:" + printBean.getCollectLocation(), 3, 0, 0, false, false);

        iPrinter.drawBarCode(375, 268, printBean.getCollectCode(), 1, 0, 2, 70);
        iPrinter.drawText(width - 80, 338, 80, 20, printBean.getCollectCode(), 1, 0, 0, false, false);
        if (StringUtils.isEmpty(printBean.getCategory())) {
            iPrinter.drawText(10, 360, 120, 100, "物品类型：其他", 2, 0, 1, false, false);
        } else {
            iPrinter.drawText(10, 360, 120, 100, "物品类型：" + printBean.getCategory(), 2, 0, 1, false, false);
        }
        iPrinter.drawText(150, 374, 480, 100, printBean.getBigCode(), 5, 0, 1, false, false);
        iPrinter.drawBarCode(190, 490, printBean.getExpressNumber(), 1, 0, 2, 70);
        iPrinter.drawText(10, 588, 200, 24, "运单编号", 2, 0, 0, false, false);
        iPrinter.drawText(210, 588, 200, 24, printBean.getExpressNumber(), 2, 0, 0, false, false);
        iPrinter.drawText(10, 630, 200, 24, "收件人/代签人：", 2, 0, 0, false, false);
        iPrinter.drawText(width - 300, 630, 300, 24, "签收日期:  年  月  日", 2, 0, 0, false, false);
        iPrinter.drawText(width - 300, 654, 300, 24, "火箭包裹- " + printBean.getBagCode(), 2, 0, 0, false, false);
        //中联
        iPrinter.drawBarCode(10, 707, printBean.getExpressNumber(), 1, 0, 2, 50);
        iPrinter.drawText(10, 760, 200, 24, printBean.getExpressNumber(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 785, 200, 20, "发件人：" + printBean.getSenderName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 805, 200, 20, "电话：" + printBean.getSenderPhone(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 825, 540, 20, "发件地址：" + printBean.getSenderAddress(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 845 + senderAddressHeight, 200, 20, "收件人：" + printBean.getReceiverName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 865 + senderAddressHeight, 200, 20, "电话：" + printBean.getReceiverPhone(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 885 + senderAddressHeight, 540, 20, "收件地址：" + printBean.getReceiverAddress(), 1, 0, 0, false, false);
        //下联
        iPrinter.drawBarCode(10, 985, printBean.getExpressNumber(), 1, 0, 2, 50);
        iPrinter.drawText(10, 1038, 200, 24, printBean.getExpressNumber(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1061, 200, 20, "发件人：" + printBean.getSenderName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1081, 200, 20, "电话：" + printBean.getSenderPhone(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1101, 540, 20, "发件地址：" + printBean.getSenderAddress(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1121 + senderAddressHeight, 200, 20, "收件人：" + printBean.getReceiverName(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1141 + senderAddressHeight, 200, 20, "电话：" + printBean.getReceiverPhone(), 1, 0, 0, false, false);
        iPrinter.drawText(10, 1161 + senderAddressHeight, 540, 20, "收件地址：" + printBean.getReceiverAddress(), 1, 0, 0, false, false);

        iPrinter.print(0, 0);

        String string = iPrinter.printerStatus();
        if ("Printing".equals(string)) {
            return true;
        } else {
            return false;
        }
    }
}
